<template>
  <div class="pd-20">
    <el-input v-model="search"
              placeholder="请输入主题名称"
              clearable
              @clear="handleQuery"
              class="w-200"></el-input>
    <el-button type="primary"
               @click="handleQuery">查询
    </el-button>
    <el-button type="primary"
               @click="handleOption(null, 'add')">新 增
    </el-button>
    <element-table :columns="columns"
                   class="mt-20"
                   :data="tableData"
                   v-loading="loading"
                   pager
                   :pageTotal="pageTotal"
                   :pageIndex="pageIndex"
                   :pageSize="pageSize"
                   @handleChangePage="handleChangePage">
      <template v-slot:edit="{row}">
        <el-button type="primary"
                   @click="handleOption(row, 'edit')">编 辑
        </el-button>
        <el-button type="danger"
                   @click="handleOption(row, 'del')">删 除
        </el-button>
        <el-button type="info"
                   @click="handleOption(row, 'material')">素材管理
        </el-button>
        <el-button type="warning"
                   @click="handleOption(row, 'forum')">临床论坛
        </el-button>
      </template>
      <template v-slot:healthName="{row}">
        <div v-if="row.healthName">
          <div v-for="(item, index) in row.healthName.split(',')"
               :key="index">
            <el-tag type="success"
                    style="margin-top:5px;">{{ item }}
            </el-tag>
          </div>
        </div>
      </template>
    </element-table>
    <theme-dialog :dataObj="dataObj"
                  v-if="isShow"
                  :visible.sync="isShow"></theme-dialog>
    <dialog-forum :dataObj="dataObj"
                  v-if="showForum"
                  :visible.sync="showForum"></dialog-forum>
  </div>

</template>
<script>
import elementTable from '@/base/ElementTable'
import themeDialog from './themeDialog'
import dialogClinicalForumIndex from "./dialogClinicalForumIndex";

export default {
  name: 'diseaseTheme', // 疾病主题管理
  data() {
    return {
      loading: false,
      isShow: false,
      showForum: false,
      columns: [
        {
          label: '主题名称',
          prop: 'name',
        },
        {
          label: '主病症',
          prop: 'diseaseName',
        },
        {
          label: '合并症',
          prop: 'complicationName',
        },
        {
          label: '推荐检测项目',
          prop: 'deviceNames',
        },
        {
          label: '推荐健康筛查项目',
          prop: 'healthName',
          isSlot: true
        },
        {
          label: '创建时间',
          prop: 'createTime',
          width: 150,
          formatter: (row, cellValue) => {
            return this.commonFunction.timestampFormat(new Date(row.createTime), 'yyyy-MM-dd hh:mm:ss')
          }
        },
        {
          label: '操作',
          prop: 'edit',
          width: 360,
          isSlot: true
        }
      ],
      tableData: [],
      search: '',
      pageTotal: 0,
      pageIndex: 1,
      pageSize: 20,
      dataObj: {}
    }
  },
  methods: {
    handleQuery() {
      this.pageIndex = 1
      this.getList()
    },
    getList() {
      this.post(this.api.promote.themeInfoList, {
        search: this.search,
        pageIndex: this.pageIndex - 1,
        pageSize: this.pageSize,
        type: 1
      }).then(res => {
        if (res.data.code === '200') {
          this.tableData = res.data.object;
          this.pageTotal = res.data.totalNum;
        }
      })
    },
    handleOption(row, op) {
      switch (op) {
        case 'add':
          this.dataObj = null;
          this.isShow = true;
          break;
        case 'edit':
          this.dataObj = Object.assign({}, row);
          this.isShow = true;
          break;
        case 'del':
          this.$confirm('您是否要删除该主题？')
            .then(async _ => {
              const {data: res} = await this.post(this.api.promote.delDiseaseTheme, {
                id: row.id
              })
              if (res.code === '200') {
                this.$message.success('删除成功!');
                this.getList();
              }
            })
            .catch(_ => {
            });
          break;
        case 'material':
          this.$router.push({name: 'material', query: {routeParams: JSON.stringify(row)}});
          break;
        case 'forum':
          this.dataObj = Object.assign({}, row);
          this.showForum = true;
          break
      }
    },
    // 分页
    handleChangePage(page) {
      this.pageIndex = page;
      this.getList();
    },
  },
  created() {
    this.getList();
  },
  components: {
    'element-table': elementTable,
    'theme-dialog': themeDialog,
    'dialog-forum':dialogClinicalForumIndex
  }
}
</script>
<style scoped lang="scss">
</style>
